package com.woniuxy.info.sys.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.info.sys.entity.Informations;
import com.woniuxy.info.sys.entity.Replies;
import com.woniuxy.info.sys.mapper.RepliesMapper;
import com.woniuxy.info.sys.model.RepliesDto;
import com.woniuxy.info.sys.service.IRepliesService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 *
 * 评论服务实现类
 */
@Service
public class RepliesServiceImpl extends ServiceImpl<RepliesMapper, Replies> implements IRepliesService {
    /**
     *
     * 保存评论
     */
    @Override
    public void saveReplies(RepliesDto repliesDto) {
        Replies replies = BeanUtil.copyProperties(repliesDto, Replies.class);
        replies.setReplyTime(new Date());
        Informations informations = new Informations();
        informations.setLastPostTime(new Date());
        baseMapper.insert(replies);
    }

    /**
     * 查询评论信息
     */
    @Override
    public List<Replies> findRepliesByInfoId(Integer infoId) {
        List<Replies> replies = baseMapper.selectList(Wrappers.lambdaQuery(Replies.class).eq(Replies::getInfoId, infoId));
        return replies;
    }
}
